package com.wb.mianxiangduixiang.bms;

import java.util.Scanner;

/**
 * @author 黄衡熙
 * @version 1.0
 * @date 2025年07月22日15:47
 */
public class BankMenu {
    private Account account;
    private Scanner sc = new Scanner(System.in);
    public Account getAccount() {
        return account;
    }

    public void setAccount(Account account) {
        this.account = account;
    }

    public BankMenu(Account account) {
        this.account = account;
    }

    public void showMenu() {
        System.out.println("*********************恭喜"+account.getName()+"成功进入紫金银行*********************");
        System.out.print("请选择服务(1.存款 2.取款 3.查询余额 4.转账 5.贷款 6.还款 7.查询贷款金额 8.修改密码 9.退出登录):");
        // 每一个服务对应一个方法
        int choices=sc.nextInt();
        switch(choices) {
            case 1:
                System.out.print("请输入您的存款金额:");
                account.deposit(sc.nextDouble());
                showMenu();
                break;
            case 2:
                System.out.print("请输入取款金额:");
                account.withdrawMoney(sc.nextDouble());
                showMenu();
                break;
            case 3:
                System.out.println("当前账户余额为:"+account.getBalance());
                showMenu();
                break;
            case 4:
                while(true) {
                    System.out.print("请输入您要转账的收款方卡号:");
                    int id = sc.nextInt();
                    Account account1 = Bank.findById(id);
                    if (account1 == null) {
                        System.out.println("提示该账户不存在,请重新输入");
                        // 如果返回值为null,说明卡号或者密码有误
                    } else {
                        System.out.println("已选定收款方");
                        System.out.print("请输入您转账的金额:");
                        account.transferMoney(sc.nextDouble(),account1);
                        showMenu();
                        break;
                    }
                }
                break;
            case 5:
                System.out.print("请输入您的贷款金额:");
                if (account instanceof Loanable) {
                    Loanable loanAccount = (Loanable) account;
                    loanAccount.providerLoan(sc.nextDouble());
                } else {
                    System.out.println("当前账户不支持贷款功能");
                }
                showMenu();
                break;
            case 6:
                System.out.print("请输入还款金额:");
                if (account instanceof Loanable) {
                    Loanable loanAccount = (Loanable) account;
                    loanAccount.payLoan(sc.nextDouble());
                }else{
                    System.out.println("当前账户不支持贷款,因此您无需还款");
                }
                showMenu();
                break;
            case 7:
                //引用类型转换
                if (account instanceof Loanable) {
                    Loanable loanAccount = (Loanable) account;
                    loanAccount.queryLoan();
                } else {
                    System.out.println("当前账户不支持贷款，因此无法查询");
                }
                showMenu();
                break;
            case 8:
                System.out.print("请输入新密码:");
                account.setPassword(sc.next());
                showMenu();
                break;
            case 9:
                System.out.println("已退出登录");
                Start start=new Start();
                start.showMenu();
                break;
        }
    }

}
